<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>燃气费查询</title>
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<link href="../../plugins/mui/mui.min.css" rel="stylesheet" />
		<link rel="stylesheet" href="../../css/life_housekeeper/wate_index.css" />
		<script src="../../js/statistics.js"></script>
		<script src="../../js/fontset.js"></script>
	</head>
	<body>
		<header class="mui-bar mui-bar-nav header">
		    <a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
		    <h1 class="mui-title">燃气费查询</h1>
		</header>
		<div class="mui-content content-vh">
			<div class="content-default">
				
				<div class="group-bg-box default-bg">
					<div class="user-img-box flex-center">
						<div class="user-img-box-line flex-center">
							<span class="user-img"><img src="" id="userImg"/></span>
						</div>
					</div>
					<div class="search-group group-top">
						<div class="group-tit mui-text-center">
							<h3 id="userName"></h3>
							<p>您当前尚未绑定户号</p>
						</div>
						<div class="search-view-cell">
							<label for="userCode" class="search-label">户号&nbsp;:</label>
							<input type="number" placeholder="请输入用户号" class="search-input input-defalut" id="userCode"/>
						</div>	
					</div>
				</div>
			    
				<div class="btn-box">
					<button class="button-primary" id="bindBtn">绑定</button>
					<p class="flex-center">燃气电话：962007</p>
				</div>
				
			</div>
			<div class="footer-img-defalut">
				<img src="../../images/icon/life_housekeeper/user-water-bg2.png" class="img-response"/>
			</div>
		</div>
		<script src="../../plugins/mui/mui.min.js"></script>
		<script src="../../js/getApiToken.js"></script>
		<script src="../../js/md5.js"></script>
		<script src="../../plugins/template/template.js"></script>
		<script src="../../js/life_housekeeper/windowTitleView.js"></script>
		<script src="../../js/my/security/index.js"></script>
		<script type="text/javascript">
			mui.init();
			mui.plusReady(function(){
				var headimgUrl = plus.storage.getItem("cg_headimgurl"),
					nickName = plus.storage.getItem("cg_nickname"),
					userName = document.getElementById("userName"),
					userImg = document.getElementById("userImg");
				userName.innerHTML = nickName;
				userImg.src = headimgUrl;
				var gasCode = plus.storage.getItem('gas_yhbh');
				if(!gasCode || gasCode == ''){
					certification(gasBind);
				}else{
					var str = '请绑定新户号';
					document.querySelectorAll(".search-group p")[0].innerHTML = str;
					gasBind(gasCode);
				}	
			})
			//燃气绑定
			function gasBind(e){
				var userId = plus.storage.getItem("cg_user_id"), 
				    userCode = document.getElementById("userCode"),
					bindBtn  = document.getElementById("bindBtn");
				bindBtn.addEventListener('tap',function(){					
					var value = userCode.value;
			    	console.log(value);
			    	if(!value || value==""){
			    		mui.toast("请输入户号!");
			    		return;
			    	}else{
			    		var reg = new RegExp("^[0-9]*$");
			    		if(!reg.test(value)){
					        mui.toast("请输入数字!");
					        return;
					    }else{
					    	plus.nativeUI.showWaiting();
					    	var data ={
					    		yhbh:value,
					    		userId:userId
					    	};
					    	if(e){
					    		var arr = e.split(','),status;
						    	for(var b in arr){
						    		if(value == arr[b]){
						    			status = true;
						    		}
						    	}
						    	if(status){
						    		mui.toast("该户号已绑定，勿重复绑定相同户号!");
						    		return;
						    	}else{
						    		data.yhbh = e +','+ value;
						    	}
						    	console.log(data.yhbh);
					    	}
					    	myAjax('home/gas/bind','post',data,function(result){
					    		plus.nativeUI.closeWaiting();
					    		//console.log(result);
					    		var state = result.code;
					    		if(state == 0){
									var viewOptions = {
										url:'gas_list.html',
										id:'gas_list'
									},
									extras ={
										code:data.yhbh
									},
									titleOptions = {
										
									};
									plus.storage.setItem('gas_yhbh',data.yhbh);
									var queryPage = plus.webview.getWebviewById('gas_list');
									if(queryPage){
										mui.fire(queryPage,'bindEvent',extras);
									}
									addTitleView(viewOptions,extras,titleOptions);
					    		}
					    	});
					    }
					}  		
				},false)
			}
			
		</script>
	</body>
</html>